package se.curalia.slimcache;

import java.net.URLEncoder;

/**
 * The Layer class
 */
public class Layer {
    String name;
    BBOX bbox;
    int zoomLevels;
    double[] resolutions;
    String uri;
    String srs;
    String layers;


    public Layer() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BBOX getBbox() {
        return bbox;
    }

    public void setBbox(BBOX bbox) {
        this.bbox = bbox;
    }

    public int getZoomLevels() {
        return zoomLevels;
    }

    public void setZoomLevels(int zoomLevels) {
        this.zoomLevels = zoomLevels;
    }

    public double[] getResolutions() {
        return resolutions;
    }

    public void setResolutions(double[] resolutions) {
        this.resolutions = resolutions;
    }

    

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getSrs() {
        return srs;
    }

    public void setSrs(String srs) {
        this.srs = srs;
    }

    public void setLayers(String s) {
        this.layers = s;
    }

    public String getUri() {
        return uri;
    }

    public String getLayers() {
        return layers;
    }

    public String toQueryString() throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(uri);
        addParam(sb, WMSRequest.REQUEST_PARAM, "GetMap", true);
        addParam(sb, WMSRequest.VERSION_PARAM, "1.1.1", false);
        addParam(sb, WMSRequest.SRS_PARAM, this.srs, false);
        addParam(sb, WMSRequest.VERSION_PARAM, "1.1.1", false);
        addParam(sb, WMSRequest.LAYER_PARAM, this.layers, false);
        return sb.toString();
    }

    private void addParam(StringBuffer sb, String name, String value, boolean first) throws Exception {
        if(!first) {
            sb.append("&");
        }
        sb.append(name).append("=").append(URLEncoder.encode(value,"UTF-8"));
    }
}
